import "./public-path";
import "./styles/normalize.css";
import React from "react";
import ReactDOM from "react-dom/client";
import { Provider } from "react-redux";
import { store } from "./models/store";
import App from "./App";

import reportWebVitals from "./reportWebVitals";

let root: ReactDOM.Root | null;
function render(props: { container?: any }) {
  const { container } = props;
  root =
    root ||
    ReactDOM.createRoot(
      container
        ? container.querySelector("#appRoot")
        : document.getElementById("appRoot")
    );
  root.render(
    <React.StrictMode>
      <Provider store={store}>
        <App />
      </Provider>
    </React.StrictMode>
  );
}

if (!window.__POWERED_BY_QIANKUN__) {
  render({});
}

export async function bootstrap() {
  console.log("[react18] react app bootstrap");
}

export async function mount(props: any) {
  console.log("[react18] props from main framework", props);
  render(props);
}

export async function unmount(props: any) {
  root?.unmount();
  root = null;
}

reportWebVitals();
